/*package utility;

import java.util.ArrayList;
import java.util.Random;

import android.util.Log;

public class Alpha_Beta {
	private int index;
	private int depthInit;
	private boolean isLoad;

	private int Eval(ArrayList<Item> items) {
		int sum = 0;
		for (Item i : items) {
			if (i.getIndex() == index) {
				sum++;
			}
		}
		return sum;
	}

	private int MaxVal(ArrayList<Item> items, int alpha, int beta, int depth,
			boolean isLoad, int movedCol, int movedRow) {
		ArrayList<Item> itemsTemp;
		int max = 0;
		if (depth == 1 || Eval(items) == 0) {
			// numberMoveBest=depthInit+1-depth;
			return Eval(items);
		} else {
			ArrayList<Item> Temp = new ArrayList<Item>();
			for (Item item : items) {
				Item temp1 = new Item(item);
				Temp.add(temp1);
			}
			boolean isLoadTemp;
			for (Item item : Temp) {
				if (item.getIndex() == index) {
					int fromCol = item.getCurrentCol();
					int fromRow = item.getCurrentRow();
					boolean loop = true;
					ArrayList<Item> itemsMoveTemp = Utility_Game.getItemsDest(Temp,
							fromCol, fromRow);
					if (itemsMoveTemp != null && itemsMoveTemp.size() > 0) {
						for (Item i : itemsMoveTemp) {
							int toCol = i.getCurrentCol();
							int toRow = i.getCurrentRow();
							Log.d("Di chuyen do", "tu (" + fromCol + ","
									+ fromRow + ") den (" + toCol + ", "
									+ toRow + ")");
							itemsTemp = null;
							itemsTemp = Utility_Game.moveItem(Temp, fromCol,
									fromRow, toCol, toRow);
							isLoadTemp = Utility_Game.checkLoad(itemsTemp, fromCol,
									fromRow, toCol, toRow);
							int a = MinVal(itemsTemp, alpha, beta, depth - 1,
									isLoadTemp, toCol, toRow);
							if (a > max)
								max = a;
							Log.d("Loi the", "c=  " + a + "   isLoadTemp="
									+ isLoadTemp);
							if (alpha < a)
								alpha = a;
							if (alpha > beta) {
								loop = false;
								break;
							}

						}
						if (!loop)
							break;
					}
				}
			}
			// return alpha;
			return max;
		}

	}

	private int MinVal(ArrayList<Item> items, int alpha, int beta, int depth,
			boolean isLoad, int movedCol, int movedRow) {
		ArrayList<Item> itemsTemp;
		int min = 16;
		if (depth == 1 || Eval(items) == 16) {
			// numberMoveBest=depthInit+1-depth;
			return Eval(items);
		} else {
			ArrayList<Item> Temp = new ArrayList<Item>();
			for (Item item : items) {
				Item temp1 = new Item(item);
				Temp.add(temp1);
			}
			boolean isLoadTemp;
			for (Item item : Temp) {
				if (item.getIndex() != index) {
					int fromCol = item.getCurrentCol();
					int fromRow = item.getCurrentRow();
					boolean loop = true;
					ArrayList<Item> itemsMoveTemp = Utility_Game.getItemsDest(Temp,
							fromCol, fromRow);
					if (itemsMoveTemp != null && itemsMoveTemp.size() > 0) {
						for (Item i : itemsMoveTemp) {
							int toCol = i.getCurrentCol();
							int toRow = i.getCurrentRow();
							Log.d("Di chuyen xanh", "tu (" + fromCol + ","
									+ fromRow + ") den (" + toCol + ", "
									+ toRow + ")");
							itemsTemp = null;
							itemsTemp = Utility_Game.moveItem(Temp, fromCol,
									fromRow, toCol, toRow);
							isLoadTemp = Utility_Game.checkLoad(itemsTemp, fromCol,
									fromRow, toCol, toRow);
							int b = MaxVal(itemsTemp, alpha, beta, depth - 1,
									isLoadTemp, toCol, toRow);
							if (b < min)
								min = b;
							Log.d("Loi the", "b=  " + b + "   isLoadTemp="
									+ isLoadTemp);
							if (beta > b)
								beta = b;
							if (alpha > beta) {
								loop = false;
								break;
							}
						}
						if (!loop)
							break;
					}
				}
			}
			return min;
		}
	}

	public ArrayList<Item> AlphaBeta(ArrayList<Item> items) {
		ArrayList<Item> itemsTemp;
		ArrayList<Item> itemsMove = new ArrayList<Item>();
		ArrayList<Item> itemsMoveBest = new ArrayList<Item>();
		ArrayList<Item> Temp = new ArrayList<Item>();
		for (Item item : items) {
			Item temp1 = new Item(item);
			Temp.add(temp1);
		}
		int alpha = 0;
		int beta = 16;
		int fromBestCol = -1;
		int fromBestRow = -1;
		int toBestCol = -1;
		int toBestRow = -1;
		int curEval = Eval(Temp);
		int numberEat = 0;
		Item temp;
		// int numberMinMove=depthInit;
		boolean isLoadTemp;
		for (Item item : Temp) {
			if (item.getIndex() == index) {
				int fromCol = item.getCurrentCol();
				int fromRow = item.getCurrentRow();
				ArrayList<Item> itemsMoveTemp = Utility_Game.getItemsDest(Temp,
						fromCol, fromRow);
				// Log.d("Kich thuoc mang nuoc di",
				// "size="+itemsMoveTemp.size()+" ("+fromCol+", "+fromRow+")");
				if (itemsMoveTemp != null && itemsMoveTemp.size() > 0) {
					for (Item i : itemsMoveTemp) {
						int toCol = i.getCurrentCol();
						int toRow = i.getCurrentRow();
						Log.d("DI CHUYEN", "tu (" + fromCol + "," + fromRow
								+ ") den (" + toCol + ", " + toRow + ")");
						itemsTemp = null;
						// numberMoveBest=depthInit;
						itemsTemp = Utility_Game.moveItem(Temp, fromCol, fromRow,
								toCol, toRow);
						int evalMove = Eval(itemsTemp);
						isLoadTemp = Utility_Game.checkLoad(itemsTemp, fromCol,
								fromRow, toCol, toRow);
						int a = MinVal(itemsTemp, alpha, beta, depthInit,
								isLoadTemp, toCol, toRow);
						Log.d("Ket qua", "alpha= " + alpha + "   a=" + a);
						if (alpha < a
								|| (alpha == a && numberEat <= (evalMove - curEval))) {

							if (alpha < a) {
								numberEat = 0;
								itemsMoveBest = null;
								itemsMoveBest = new ArrayList<Item>();
								Log.d("Xoa mang 1", "alpha= " + alpha + "   a="
										+ a);
							} else if (numberEat < (evalMove - curEval)) {
								itemsMoveBest = null;
								itemsMoveBest = new ArrayList<Item>();
								Log.d("Xoa mang 2", "alpha= " + alpha + "   a="
										+ a);
							}
							alpha = a;
							temp = new Item();
							temp.setPreviousCol(fromCol);
							temp.setPreviousRow(fromRow);
							temp.setCurrentCol(toCol);
							temp.setCurrentRow(toRow);
							itemsMoveBest.add(temp);
							Log.d("DI CHUYEN", "tu (" + fromCol + "," + fromRow
									+ ") den (" + toCol + ", " + toRow + ")");
						}
					}
				}
			}
		}
		int size = itemsMoveBest.size();
		Log.d("Loi the", "size= " + size);
		if (size > 0) {
			Random rand = new Random();
			int choose = rand.nextInt(size);
			fromBestCol = itemsMoveBest.get(choose).getPreviousCol();
			fromBestRow = itemsMoveBest.get(choose).getPreviousRow();
			toBestCol = itemsMoveBest.get(choose).getCurrentCol();
			toBestRow = itemsMoveBest.get(choose).getCurrentRow();
			itemsMove = Utility_Game.moveItem(items, fromBestCol, fromBestRow,
					toBestCol, toBestRow);
			isLoad = Utility_Game.checkLoad(itemsMove, fromBestCol, fromBestRow,
					toBestCol, toBestRow);
			if (isLoad) {
				// Ingame.soundtoforce.start();
			} else {
				// Ingame.soundGo.start();
			}
			// Log.d("Di chuyen", "tu ("+fromBestCol+","+ fromBestRow+") den ("+
			// toBestCol+", "+ toBestRow+")");
		} else {
			for (Item item : items) {
				Item temp1 = new Item(item);
				itemsMove.add(temp1);
			}
		}
		return itemsMove;

	}

	public int getDepthInit() {
		return depthInit;
	}

	public void setDepthInit(int depthInit) {
		this.depthInit = depthInit;
	}

}
*/